package com.cq.jackmar.rxdemo.demo;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.LinearLayoutManager;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cq.jackmar.rxdemo.R;
import com.cq.jackmar.rxdemo.base.BaseActivity;
import com.cq.jackmar.rxdemo.view.rvlist.RecycleViewDivider;
import com.cq.jackmar.rxdemo.view.rvlist.view.JRecyclerView;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by JackMar on 2017/3/10.
 * 邮箱：1261404794@qq.com
 */

public class JRecyclerViewActivity extends BaseActivity {
    @Bind(R.id.jrv_list)
    JRecyclerView mJrvList;
    private CommonAdapter<String> mAdapter;
    private List<String> strings = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.activity_jrecyclerview;
    }

    @Override
    protected void initView() {
//        for (int i = 0; i < 30; i++) {
//            strings.add("1");
//        }
        mJrvList.setGridLayout(2);
        mJrvList.addItemDecoration(new RecycleViewDivider(context, LinearLayoutManager.HORIZONTAL, 1, 0, 0, Color.parseColor("#cccccc")));
        mAdapter = new CommonAdapter<String>(context, R.layout.cell_list, strings) {
            @Override
            protected void convert(ViewHolder holder, String s, int position) {
                holder.setText(R.id.tv_text, "接口连接");
            }
        };
        mJrvList.setAdapter(mAdapter);
        TextView textView = new TextView(context);
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 600);
        textView.setLayoutParams(layoutParams);
        textView.setBackgroundColor(Color.parseColor("#ff0000"));
        mJrvList.setEmptyView(textView);
        mJrvList.showEmptyView();
    }

    @Override
    protected void initData() {
        mJrvList.setOnRefreshListener(new JRecyclerView.JRecyclerViewListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mJrvList.setRefreshCompleted();
                    }
                }, 2000);
            }

            @Override
            public void onLoadMore() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mJrvList.setRefreshCompleted();
                    }
                }, 2000);

            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
